function [L2meanResd] = cfdCalculateL2meanResd
%--------------------------------------------------------------------------
%  Written by LiuHaHa @ NWPU, 2022 01 
%  Contact me at: liuzhikan@mail.nwpu.edu.cn
%==========================================================================
% Routine Description:
%   This function calculate L2meanResd
%--------------------------------------------------------------------------
global cfdFlow;
phyTemp = cfdFlow.Phy;
phyPreOutput = cfdFlow.phyPreOutput;
theNumberOfElements = cfdFlow.mesh.numberOfElements;

%  only for the energy equation
resd = abs(dot((phyTemp(1:theNumberOfElements,end) - phyPreOutput(1:theNumberOfElements,end)), ... 
           (phyTemp(1:theNumberOfElements,end) - phyPreOutput(1:theNumberOfElements,end))));
      
sumResd = sum(resd);       
L2meanResd = sqrt(sumResd/theNumberOfElements);

end